/**
 * @Author YuanYuan
 * @Date 2022/5/7
 * @Time 10:17
 */
public class TestDemo {
    public static int binarySearch(int[] arr,int num) {
        int left = 0;
        int right = arr.length;
        while(left<=right) {
            int mid = (left+right)/2;
            if(arr[mid]<num) {
                left = mid+1;
            }else if(arr[mid]>num) {
                right = mid - 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        int ret = binarySearch(arr,6);
        System.out.println(ret);
    }
}
